package com.cheng.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cheng.common.exception.CommonException;
import com.cheng.common.utils.StringUtil;
import com.cheng.data.entity.CompanyBaseInfoEntity;
import com.cheng.data.mapper.CompanyBaseInfoMapper;
import com.cheng.data.vo.CompanyBaseInfoVO;
import com.cheng.service.CompanyBaseInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: ChengJW
 * @date: 2021/11/7 21:35
 * @version: 1.0
 * @description: 有关 companyBaseInfo 表的操作。
 */
@Service
public class CompanyBaseInfoServiceImpl implements CompanyBaseInfoService {
    
    private final static Logger log = LoggerFactory.getLogger(CompanyBaseInfoServiceImpl.class);

    @Autowired
    private CompanyBaseInfoMapper companyBaseInfoMapper;

    /**
    * @author: ChengJW
    * @params: []
    * @return: com.cheng.data.vo.CompanyBaseInfoVO
    * @date: 2021/11/7
    * @description: 根据条件查询企业信息
    */
    @Override
    public List<CompanyBaseInfoEntity> queryCompanyBaseInfo(CompanyBaseInfoEntity entity) throws CommonException {

        if (null == entity){
            log.error("CompanyBaseInfoEntity is null");
            throw new CommonException("CJW2021E041","CompanyInfoServiceImpl","queryCCompanyBaseInfo");
        }
        QueryWrapper<CompanyBaseInfoEntity> wrapper = new QueryWrapper<>();
        //受理号
        wrapper.eq(StringUtil.isNotNull(entity.getCyAcptId()),"cy_Acpt_Id",entity.getCyAcptId());
        //主键
        wrapper.eq(StringUtil.isNotNull(entity.getCyId()),"cy_Id",entity.getCyId());
        //统一社会信用代码
        wrapper.eq(StringUtil.isNotNull(entity.getCyCreditCode()),"cy_Credit_Code",entity.getCyCreditCode());
        //注册号
        wrapper.eq(StringUtil.isNotNull(entity.getCyRegistId()),"cy_Regist_Id",entity.getCyRegistId());
        //企业名称
        wrapper.like(StringUtil.isNotNull(entity.getCyNm()),"cy_Nm",entity.getCyNm());
        //商事主体类型
        wrapper.eq(StringUtil.isNotNull(entity.getCyBussType()),"cy_Buss_Type",entity.getCyBussType());
        //是否登记
        wrapper.eq(StringUtil.isNotNull(entity.getCyRegistCd()),"cy_Regist_Cd",entity.getCyRegistCd());
        //所属单位
        wrapper.eq(StringUtil.isNotNull(entity.getCyMgeCode()),"cy_Mge_Code",entity.getCyMgeCode());
        CompanyBaseInfoVO companyBaseInfoVO = new CompanyBaseInfoVO();
        return companyBaseInfoMapper.selectList(wrapper);
    }

    /**
     * @author: ChengJW
     * @params: [entity]
     * @return: int
     * @date: 2021/9/20
     * @description: 根据 id 修改 companyBaseInfo 信息
     */
    @Override
    public int updateCompanyBaseInfo(CompanyBaseInfoEntity entity) throws CommonException {
        return companyBaseInfoMapper.updateById(entity);
    }
}
